<%--
  Created by IntelliJ IDEA.
  User: Jackey
  Date: 2016-08-12
  Time: 16:06
--%>

<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>金格网新闻发布管理端</title>
    <asset:stylesheet src="demo.css"/>
    <asset:stylesheet src="themes/default/easyui.css"/>
    <asset:stylesheet src="themes/icon.css"/>
    <asset:javascript src="jquery.min.js"/>
    <asset:javascript src="jquery.easyui.min.js"/>
    <script>
        $('#cc').combo({
            required:true,
            multiple:true,
            url:"EasyUI/getProductTypeList"
        });

        function newData(){
            $('#dlg').dialog('open').dialog('setTitle','新增新闻');
            $('#fm').form('clear');
            url = 'EasyUI/createNews';
        }

        function editData() {
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('setTitle','修改新闻');
                $('#fm').form('load',row);
                url = 'EasyUI/updateNews?id='+row.id;
            }
        }

        function saveData(){
            $('#fm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){
                    var result = eval('('+result+')');
                    if (result.errorMsg){
                        $.messager.show({
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    } else {
                        $('#dlg').dialog('close');        // close the dialog
                        $('#dg').datagrid('reload');    // reload the user data
                    }
                }
            });
        }
        function destroyData(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('提示','确认删除当前选择的新闻信息?',function(r){
                    if (r){
                        $.post('EasyUI/deleteNews',{id:row.id},function(result){
                            if (result.success){
                                $('#dg').datagrid('reload');    // reload the user data
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
    </script>
</head>
<body>
    <table id="dg" title="新闻列表" class="easyui-datagrid" style="width:100;height:100"
           url="newsList/index"
           toolbar="#toolbar"
           rownumbers="true" fitColumns="true" singleSelect="true">
        <thead>
            <tr>
                <th field="id" hidden="true"></th>
                <th field="title" width="50">标题</th>
                <th field="URL" width="50">URL</th>
                <th field="createDate" width="50">创建日期</th>
                <th field="ProductType" width="50">新闻类别</th>
            </tr>
        </thead>
    </table>
    <!--工具条-->
    <div id="toolbar">
        新闻类别:
        <select id="cc" class="easyui-combobox" panelHeight="auto" style="width:200px"
                url="EasyUI/getProductTypeList"
                valueField="id" textField="productTypeName">
        </select>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newData()">新增</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editData()">修改</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyData()">删除</a>
    </div>

    <div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
         closed="true" buttons="#dlg-buttons">
        %{--<div class="ftitle">新闻信息</div>--}%
        <form id="fm" method="post" novalidate>
            <div class="fitem">
                <label>新闻标题:</label>
                <input name="title" class="easyui-textbox" required="true" style="width: 100%">
            </div>
            <div class="fitem">
                <label>新闻地址:</label>
                <input name="URL" class="easyui-textbox" required="true" style="width: 100%">
            </div>
            %{--<div class="fitem">--}%
                %{--<label>创建日期:</label>--}%
                %{--<input name="createDate" class="easyui-datebox"--}%
                       %{--required="true" style="width: 350px">--}%
            %{--</div>--}%
            <div class="fitem">
                <label>新闻类别:</label>
                <input name="productType" class="easyui-combobox"
                       url="EasyUI/getProductTypeList"
                       valueField="id" textField="productTypeName"
                       required="true" style="width: 350px">
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveData()" style="width:90px">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
    </div>
</body>
</html>